package com.yuyang.wifi.activitys.mine;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.yuyang.wifi.R;
import com.yuyang.wifi.base.BaseActivity;
import com.yuyang.wifi.base.BaseResult;
import com.yuyang.wifi.utils.RxUtil;
import com.yuyang.wifi.utils.ToastUtils;
import com.yuyang.wifi.utils.network.BaseDataSubscriber;
import com.yuyang.wifi.utils.network.HttpErrorHandler;
import com.yuyang.wifi.utils.network.HttpManager;
import com.yuyang.wifi.utils.network.RxDataInstance;
import com.yuyang.wifi.views.CustomEditText;
import com.yuyang.wifi.views.NormalWhiteTopBar;

import butterknife.BindView;
import butterknife.OnClick;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class SuggestReturnActivity extends BaseActivity {

    @BindView(R.id.tool_bar)
    NormalWhiteTopBar toolBar;
    @BindView(R.id.custom_edit_text)
    CustomEditText customEditText;
    @BindView(R.id.input_contract_war)
    EditText inputContractWar;

    private String mContent;
    private String mContractWar;

    @Override
    protected void initActionBar() {
        toolBar.setActionBarCentreTitle("意见反馈");
        toolBar.setsetActionBarBottomLine(false);
        toolBar.setsetActionBarLeftIcon(R.mipmap.toolbar_left_arrow_back_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_suggest_return;
    }

    @Override
    protected void initContentView() {


    }

    @OnClick(R.id.tv_immediately_binding)
    public void onViewClicked() {
        mContent = customEditText.getInputEdit().getText().toString();
        mContractWar = inputContractWar.getText().toString().trim();
        if (TextUtils.isEmpty(mContent) || mContent.length() == 0) {
            com.yuyang.wifi.utils.ToastUtils.showShortToast(SuggestReturnActivity.this, "输入内容不能为空");
            return;
        }
        commitSuggest();
    }

    private void commitSuggest() {
        RxDataInstance.getInstance().initMap(SuggestReturnActivity.this)
                .put("msg", mContent)
                .put("contact", mContractWar);
        HttpManager.getInstance().getApi().SuggestReturn(RxDataInstance.getInstance().getParamMap())
                .compose(RxUtil.<BaseResult>bindLifecycleAndApplySchedulers(this))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseDataSubscriber<BaseResult>(new HttpErrorHandler() {
                    @Override
                    public void onHttpError(BaseResult result) {
                        com.yuyang.wifi.utils.ToastUtils.showShortToast(SuggestReturnActivity.this, result.getErrorMessage());
                    }

                    @Override
                    public void onHttpException(Throwable e) {
                        // dismissLoadingDialog();
                    }
                }) {
                    @Override
                    public void onDataNext(BaseResult result) {
                        int resultCode = result.getResultCode();
                        if (0 == resultCode) {
                            ToastUtils.showShortToast(SuggestReturnActivity.this, "反馈成功");
                            finish();
                        } else {
                            ToastUtils.showShortToast(SuggestReturnActivity.this, result.getErrorMessage());
                        }
                    }
                });

    }
}
